package 常用类.日期;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class date01 {
    public static void main(String[] args) throws ParseException {
        Date date = new Date();
        System.out.println(date);

        //日期的格式输出，日期到字符串
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 hh:mm:ss E");
        System.out.println(simpleDateFormat.format(date));

        System.out.println(simpleDateFormat.format(new Date(System.currentTimeMillis())));

        String s1 = "2022年01月22日 02:52:24 星期六";
        Date parse = simpleDateFormat.parse(s1);
        System.out.println(parse);

        //Calendar 日历类 抽象类
        Calendar c = Calendar.getInstance();
        System.out.println(c);
        System.out.println("年：" + c.get(Calendar.YEAR));
        System.out.println("月：" + c.get(Calendar.MONTH) + 1);
        System.out.println("日：" + c.get(Calendar.DAY_OF_MONTH));
        System.out.println("时：" + c.get(Calendar.HOUR_OF_DAY));
        System.out.println("分：" + c.get(Calendar.MINUTE));
        System.out.println("秒：" + c.get(Calendar.SECOND));
    }
}
